import axios from './axios';

import {
    LOGIN,
    USERLIST,
    ADMINADD,
    USERSTATUS,
    USEREDIT,
    USERDEL,

    AUTHEDIT,
    AUTHSTATUS,
    AUTHDEL,
    AUTHADD,
    AUTHLIST,

    ROLELIST,
    ROLEADD,
    ROLEONE,
    ROLEEDIT,
    ROLEDEL,

    CATLIST,
    CATADD,
    CATEDIT,
    CATDEL,

    DISHLIST,
    DISHADD,
    DISHEDIT,
    DISHDEL,

    DATACOUNT
} from './url'

import { AxiosReponse } from 'axios'

/* -------- 用户相关 ---------- */
// 登录
interface loginData {
    username: string,
    password: string
}
export function adminLogin(data: loginData): Promise<AxiosReponse> {
    return axios(LOGIN, {
        method: 'POST',
        data
    })
}

//用户添加
export function adminAdd(data: any) {
    return axios(ADMINADD, {
        method: 'POST',
        data
    })
}

// 用户列表
export function userList() {
    return axios(USERLIST)
}

// 修改用户启用状态
export function changeEnable(id: any) {
    return axios.put(USERSTATUS + '/' + id)
}

// 用户修改
export function userEdit(data: any) {
    return axios(USEREDIT + '/' + data._id, {
        method: 'put',
        data
    })
}


// 用户删除
export function userDel(id: any) {
    return axios.delete(USERDEL + '/' + id)
}

/* -------- 权限相关 --------- */
// 获取所有权限
export function authList() {
    return axios(AUTHLIST)
}

// 切换权限状态
export function changeShowStatus(id: any) {
    return axios.put(AUTHSTATUS + '/' + id)
}

// 权限修改
export function authEdit(data: any) {
    return axios(AUTHEDIT + '/' + data._id, {
        method: 'put',
        data
    })
}

// 权限删除
export function authDel(id: any) {
    return axios.delete(AUTHDEL + '/' + id)
}

// 权限添加
export function authAdd(data: any) {
    return axios(AUTHADD, {
        method: 'post',
        data
    })
}


/* -------- 角色相关 --------- */
// 角色列表
export function roleList() {
    return axios(ROLELIST)
}

// 角色删除
export function roleDel(id: any) {
    return axios.delete(ROLEDEL + '/' + id)
}

// 角色新增
export function roleAdd(data: any) {
    return axios(ROLEADD, {
        method: 'post',
        data
    })
}

// 角色修改
export function roleEdit(data: any) {
    return axios(ROLEEDIT + '/' + data.id, {
        method: 'put',
        data
    })
}

// 获取单个角色
export function roleOne(id: any) {
    return axios(ROLEONE + '/' + id)
}

/* -------- 商品相关 -------- */
// 获取商品列表
export function dishList() {
    return axios(DISHLIST)
}

// 商品添加
export function dishAdd(data: any) {
    return axios(DISHADD, {
        method: 'post',
        data
    })
}

// 商品修改
export function dishEdit(data: any) {
    return axios(DISHEDIT + '/' + data._id, {
        method: 'put',
        data
    });
}

// 商品删除
export function dishDel(id: any) {
    return axios.delete(DISHDEL + '/' + id)
}

/* --------- 分类相关--------- */
// 获取分类列表
export function catList() {
    return axios(CATLIST)
}

// 分类添加
export function catAdd(data: any) {
    return axios(CATADD, {
        method: 'post',
        data
    })
}

// 分类修改
export function catEdit(data: any) {
    return axios(CATEDIT + '/' + data.id, {
        method: 'put',
        data: {
            catname: data.catname
        }
    })
}

// 分类删除
export function catDel(id: any) {
    return axios.delete(CATDEL + '/' + id)
}

/* ------ 统计数据 --------- */
// 主页
export function dataCount() {
    return axios(DATACOUNT)
}